.PHONY: clean all
CFLAGS = -Wall -O1 -g -march=native
#CFLAGS += -I../min_list -march=native
CLIBS = -lm -lopenblas -laio -lpthread
cc = g++

TARGET_FLOAT = annlite_test_float32
TARGET_UINT8 = annlite_test_uint8
sources = annlite_test.cpp min_list/min_list.cpp
objects = $(sources:.cpp=.o)
# 自动发现profiler目录下的所有cpp文件
profiler_sources = $(wildcard profiler/*.cpp)
profiler_objects = $(profiler_sources:.cpp=)

# 正确添加头文件依赖的方式
profiler/io_profiler: profiler/io_profiler.cpp profiler/statis.h
profiler/cal_profiler: profiler/cal_profiler.cpp profiler/statis.h

all: $(TARGET_FLOAT) $(TARGET_UINT8)
	@echo "Done!"

# 编译float版本
$(TARGET_FLOAT): 
	$(cc) $(CFLAGS) -DFTYPE=float -c annlite_test.cpp -o annlite_test_float.o
	$(cc) $(CFLAGS) -DFTYPE=float annlite_test_float.o $(CLIBS) -o $@
	rm -f annlite_test_float.o

# 编译uint8版本
$(TARGET_UINT8): 
	$(cc) $(CFLAGS) -DFTYPE=uint8_t -c annlite_test.cpp -o annlite_test_uint8.o
	$(cc) $(CFLAGS) -DFTYPE=uint8_t annlite_test_uint8.o $(CLIBS) -o $@
	rm -f annlite_test_uint8.o

clean:
	rm -f $(TARGET_FLOAT) $(TARGET_UINT8)
	rm -f $(profiler_objects)

print_args:
	@echo "CFLAGS = $(CFLAGS)"
	@echo "CLIBS = $(CLIBS)"
	@echo "cc = $(cc)"
	@echo "targets = $(targets)"
	@echo "sources = $(sources)"
	@echo "objects = $(objects)"
	@echo "profiler_sources = $(profiler_sources)"
	@echo "profiler_objects = $(profiler_objects)"

profiler: $(profiler_objects)
	@echo "Profiler compile Done!"

# 使用模式规则自动为每个profiler源文件生成目标
% : %.cpp
	$(cc) $(CFLAGS) $< $(CLIBS) -o $@

run_f:
	./$(TARGET_FLOAT)

run_i:
	./$(TARGET_UINT8)

debug:
	gdb ./$(targets)
